package com.hbjycl.entity;

import java.util.Collection;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 管理员
 * 
 * @author wxp
 *
 * @datetime 2014年8月20日下午4:13:03
 */
@Entity
public class Admin extends BaseEntity 
{
    private static final long     serialVersionUID = -7458991369464875076L;
    private String                username;                                // 用户名
    private String                password;                                // 密码
    private String                phone;                                   // 电话
    private String                mobile;                                  // 手机
    private String                email;                                   // E-mail
    private String                name;                                    // 姓名
    private String                department;                              // 部门
    private String                zjuAccount;
    private Boolean               isBound;
    private Boolean               isAccountEnabled;                        // 账号是否启用
    private Boolean               isAccountLocked;                         // 账号是否锁定
    private Boolean               isAccountExpired;                        // 账号是否过期
    private Boolean               isCredentialsExpired;                    // 凭证是否过期
    private Integer               loginFailureCount;                       // 连续登录失败的次数
    private Date                  lockedDate;                              // 账号锁定日期
    private Date                  loginDate;                               // 最后登录日期
    private String                loginIp;                                 // 最后登录IP
    private Set<Role>             roleSet;                                 // 角色
    private Set<GrantedAuthority> authorities;                             // 角色信息
    
    @Column(updatable = false, nullable = false, unique = true)
    public String getUsername()
    {
        return username;
    }
    
    @Column(nullable = false)
    public String getPassword()
    {
        return password;
    }
    
    @Column(nullable = false)
    public String getEmail()
    {
        return email;
    }
    
    public void setEmail(String email)
    {
        this.email = email;
    }
    
    public String getName()
    {
        return name;
    }
    
    public void setName(String name)
    {
        this.name = name;
    }
    
    public String getDepartment()
    {
        return department;
    }
    
    public void setDepartment(String department)
    {
        this.department = department;
    }
    
    @Column(nullable = false)
    public Boolean getIsAccountEnabled()
    {
        return isAccountEnabled;
    }
    
    public void setIsAccountEnabled(Boolean isAccountEnabled)
    {
        this.isAccountEnabled = isAccountEnabled;
    }
    
    @Column(nullable = false)
    public Boolean getIsAccountLocked()
    {
        return isAccountLocked;
    }
    
    public void setIsAccountLocked(Boolean isAccountLocked)
    {
        this.isAccountLocked = isAccountLocked;
    }
    
    @Column(nullable = false)
    public Boolean getIsAccountExpired()
    {
        return isAccountExpired;
    }
    
    public void setIsAccountExpired(Boolean isAccountExpired)
    {
        this.isAccountExpired = isAccountExpired;
    }
    
    @Column(nullable = false)
    public Boolean getIsCredentialsExpired()
    {
        return isCredentialsExpired;
    }
    
    public void setIsCredentialsExpired(Boolean isCredentialsExpired)
    {
        this.isCredentialsExpired = isCredentialsExpired;
    }
    
    @Column(nullable = false)
    public Integer getLoginFailureCount()
    {
        return loginFailureCount;
    }
    
    public void setLoginFailureCount(Integer loginFailureCount)
    {
        this.loginFailureCount = loginFailureCount;
    }
    
    public Date getLockedDate()
    {
        return lockedDate;
    }
    
    public void setLockedDate(Date lockedDate)
    {
        this.lockedDate = lockedDate;
    }
    
    public Date getLoginDate()
    {
        return loginDate;
    }
    
    public void setLoginDate(Date loginDate)
    {
        this.loginDate = loginDate;
    }
    
    public String getLoginIp()
    {
        return loginIp;
    }
    
    public void setLoginIp(String loginIp)
    {
        this.loginIp = loginIp;
    }
    
    public void setUsername(String username)
    {
        this.username = username;
    }
    
    public void setPassword(String password)
    {
        this.password = password;
    }
    
    public void setAuthorities(Set<GrantedAuthority> authorities)
    {
        this.authorities = authorities;
    }
    
    public String getPhone()
    {
        return phone;
    }
    
    public void setPhone(String phone)
    {
        this.phone = phone;
    }
    
    public String getMobile()
    {
        return mobile;
    }
    
    public void setMobile(String mobile)
    {
        this.mobile = mobile;
    }
    
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    @OrderBy("name asc")
    public Set<Role> getRoleSet()
    {
        return roleSet;
    }
    
    public void setRoleSet(Set<Role> roleSet)
    {
        this.roleSet = roleSet;
    }
    
    @Transient
    public Collection<? extends GrantedAuthority> getAuthorities()
    {
        return authorities;
    }
    
    public String getZjuAccount()
    {
        return zjuAccount;
    }
    
    public void setZjuAccount(String zjuAccount)
    {
        this.zjuAccount = zjuAccount;
    }
    
    public Boolean getIsBound()
    {
        return isBound;
    }
    
    public void setIsBound(Boolean isBound)
    {
        this.isBound = isBound;
    }
    
}
